package cn.initcap.concurrency.concurrency.immutable;

import cn.initcap.concurrency.annoations.ThreadSafe;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import lombok.extern.slf4j.Slf4j;

/**
 * 不使用final修饰变量，让变量不可变，编译不会报错，但是运行时会报错，这种方式是线程安全的。
 *
 * @author initcap
 * @date Created in 2018/6/15 PM6:36.
 */
@Slf4j
@ThreadSafe
public class ImmutableExcample3 {

    private static final ImmutableList LIST = ImmutableList.of(1, 2, 3);

    private static final ImmutableSet SET = ImmutableSet.copyOf(LIST);

    private static final ImmutableMap<Integer, Integer> MAP = ImmutableMap.of(1, 2, 3, 4);

    private static final ImmutableMap<Integer, Integer> MAP2 = ImmutableMap.<Integer, Integer>builder()
            .put(1, 2).put(3, 4).build();

    public static void main(String[] args) {
        LIST.add(4);
        MAP.put(5, 6);
        MAP2.put(5, 6);
    }

}
